/**青蛙动画换装系统 */
class FrogReloadingSystem {
	/**单例 */
	private static frogReloadingSystemSole: FrogReloadingSystem;
	/**换装部位 */
	private changeParts = ["weiba", "tou", "youhou", "zuohou", "youqian", "zuoqian"];
	/**构造 */
	private constructor() {
	}
	/**获取单例对象 */
	public static GetInstance(): FrogReloadingSystem {
		if (this.frogReloadingSystemSole == null) {
			this.frogReloadingSystemSole = new FrogReloadingSystem();
		}
		return this.frogReloadingSystemSole;
	}
	/**换装（解析数据）
	 * @param animationObj 动画对象
	 * @param type 颜色
	 * @param level 等级
	 */
	public Reloading(animationObj: any, type: number, level: number) {
		/**主要等级 */
		let mainLevel = Math.floor(level / 10);
		/**换装部位名字 */
		let changePartsName: string;
		/**当前循环等级 */
		let nowLevel: number;
		/**龙骨对象 */
		let armature = animationObj.armature;
		/**本等级部位是否有 */
		let isHaveByNowClass: boolean;
		/**插槽 */
		let slot;
		for (let i = 0; i < this.changeParts.length; i++) {
			changePartsName = null;
			nowLevel = null;
			isHaveByNowClass = true;
			//6个等级
			for (let j = 1; j < 7; j++) {
				nowLevel = mainLevel * 10 + j;
				changePartsName = this.changeParts[i] + nowLevel;
				slot = armature.getSlot(changePartsName);
				if (slot == null) {
					if (nowLevel == level) {
						isHaveByNowClass = false;
					}
					continue;
				} else {
					if (nowLevel != level) {
						slot.visible = false;
					} else {
						slot.visible = true;
						slot.displayIndex = type;
					}
				}
			}
			//如果没有本等级的插槽，换前等级的插槽
			if (!isHaveByNowClass) {
				for (let k = level % 10; k >= 1; k--) {
					nowLevel = mainLevel * 10 + k;
					changePartsName = this.changeParts[i] + nowLevel;
					slot = armature.getSlot(changePartsName);
					if (slot == null) {
						continue;
					} else {
						slot.visible = true;
						slot.displayIndex = type;
						break;
					}
				}
			}

		}
	}
}